﻿// <copyright file="BloodPowersGM.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication
{
    using LightSwitchApplication.Export;
    using LightSwitchApplication.Import;
    using LightSwitchApplication.UserCode;
    using Microsoft.LightSwitch.Presentation.Extensions;

    public partial class BloodAbilitiesGM
    {
        #region Add/Edit BloodAbility

        partial void gridAddAndEditNew_Execute()
        {
            var ability = this.Collection.AddNew();
            ability.Visibility = (int)VisibilityEnum.Public;

            this.FindControl("ModalWindow").DisplayName = "Add new Blood Ability";
            this.OpenModalWindow("ModalWindow");
        }

        partial void gridEditSelected_CanExecute(ref bool result)
        {
            result = this.Collection.SelectedItem != null;
        }

        partial void gridEditSelected_Execute()
        {
            this.FindControl("ModalWindow").DisplayName = string.Format("Edit {0}", this.Collection.SelectedItem.Name);
            this.OpenModalWindow("ModalWindow");
        }

        partial void SubmitModalWindow_Execute()
        {
            this.CloseModalWindow("ModalWindow");
        }

        partial void CancelModalWindow_Execute()
        {
            this.CloseModalWindow("ModalWindow");
            this.Collection.SelectedItem.Details.DiscardChanges();
        }

        #endregion

        #region Add Trait

        partial void RelationBloodPowerTraitsAddAndEditNew_Execute()
        {
            this.RelationBloodPowerTraits.AddNew();

            this.FindControl("ModalTrait").DisplayName = "Add Trait";
            this.OpenModalWindow("ModalTrait");
        }

        partial void SubmitModalTrait_Execute()
        {
            this.CloseModalWindow("ModalTrait");
        }

        partial void CancelModalTrait_Execute()
        {
            this.CloseModalWindow("ModalTrait");
            this.RelationBloodPowerTraits.SelectedItem.Details.DiscardChanges();
        }

        #endregion

        partial void Import_Execute()
        {
            ImporterHelper.ImportBloodAbilities(this.DataWorkspace, this.Collection);
        }

        partial void Export_Execute()
        {
            Exporter.ExportBloodAbilities(this.Collection);
        }
    }
}
